package com.nightsoul.springboottest2.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nightsoul.springboottest2.domain.User;
import com.nightsoul.springboottest2.service.UserService;

@RestController
public class UserController {
	@Resource
	private UserService userService;

	@RequestMapping("/users")
	public List<User> getUsers() {
		return this.userService.getUsers();
	}

	@RequestMapping("/user/save")
	public String saveUser() {
		String random = UUID.randomUUID().toString();
		User user = new User(random, random, random + "@126.com", random, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.userService.saveUser(user);
		return "save user success";
	}
}
